package com.gimi.cloud.bbp.manage.consumer.service.sys.impl;

import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.dto.sys.SysRoleDTO;
import com.gimi.cloud.bbp.manage.consumer.feign.SystemFeignService;
import com.gimi.cloud.bbp.manage.consumer.service.sys.SysRoleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 角色相关接口实现类
 * @author wbj
 * @version 1.0
 * @Description
 * @create 2018-01-26
 **/
@Service
public class SysRoleServiceImpl implements SysRoleService{
    private static final Logger logger = LoggerFactory.getLogger(SysRoleServiceImpl.class);
    private SystemFeignService systemFeignService;

    @Autowired
    public SysRoleServiceImpl(SystemFeignService systemFeignService) {
        this.systemFeignService = systemFeignService;
    }

    @Override
    public Response getRoleList(HttpServletRequest request, HttpServletResponse response, SysRoleDTO roleDTO) throws Exception {
        return systemFeignService.getRoleList(roleDTO);
    }

    @Override
    public Response getRoleInfo(HttpServletRequest request, HttpServletResponse response, SysRoleDTO roleDTO) throws Exception {
        if(null == roleDTO.getRoId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"角色id为空，获取角色信息失败");
            return resp;
        }
        return systemFeignService.getRoleInfo(roleDTO);
    }

    @Override
    public Response addRole(HttpServletRequest request, HttpServletResponse response, SysRoleDTO roleDTO) throws Exception {
        if(null != roleDTO.getRoId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"角色Id不为空，添加角色信息失败");
            return resp;
        }
        return systemFeignService.saveRole(roleDTO);
    }

    @Override
    public Response editRole(HttpServletRequest request, HttpServletResponse response, SysRoleDTO roleDTO) throws Exception {
        if(null == roleDTO.getRoId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"角色Id为空，编辑角色信息失败");
            return resp;
        }
        return systemFeignService.saveRole(roleDTO);
    }

    @Override
    public Response deleteRole(HttpServletRequest request, HttpServletResponse response, SysRoleDTO roleDTO) throws Exception {
        if(null == roleDTO.getRoId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"角色Id为空，删除角色信息失败");
            return resp;
        }
        return systemFeignService.deleteRole(roleDTO);
    }
}
